package Execute;

import java.sql.ResultSet;
import java.sql.SQLException;

import javax.jms.JMSException;

import sender.Producer;


import creation.DB;

public class MessagesSender {

	/**
	 * @param args
	 * @throws ClassNotFoundException 
	 * @throws IllegalAccessException 
	 * @throws InstantiationException 
	 * @throws SQLException 
	 * @throws JMSException 
	 */
	public void sendMessages(String port) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, JMSException {
		DB db = new DB("jdbc:hsqldb:file:myEmbeddedDataBase", "sa", "");
		
		ResultSet resultat = db.executeQuery("SELECT * FROM messages");
		

		Producer producer = new Producer();
		producer.openConnection("failover://tcp://localhost:"+port);
		
		while(resultat.next()){
			producer.send("messagesTopic", resultat.getString("name"));
		}
		producer.closeConnection();
		
		db.closeDB();
	}

}
